/**
 * Created by limx on 2016/12/4.
 */
$(function () {
    $(".date").calendar({
        value: ['2015-12-05']
    });

    $("#upload").change(function (event) {
        if (!isCanvasSupported()) {
            $.toast("不支持画布！");
            return;
        }
        CanvasCompress(event, 500, 0, function (data) {
            var url = $("#postUrl").val();
            var json = {
                "data": data
            };
            $.post(url, json, function (jsonData) {
                if (jsonData.status == 1) {
                    $("#pic").get(0).src = jsonData.data.x_data;
                    $("#avatar").val(jsonData.data.data);
                } else {
                    $.alert(jsonData.message);
                }
            }, "json");
        });
    });
});

function sub(e) {
    var name = $("#name").val();
    var sex = $("#sex").val();
    var cert = $("#cert").val();
    var nation = $("#nation").val();
    var birthday = $("#birthday").val();
    var school = $("#school").val();
    var edu = $("#edu").val();
    var depart = $("#depart").val();
    var class1 = $("#class").val();
    var pro = $("#pro").val();
    var card = $("#card").val();
    var edu_type = $("#edu_type").val();
    var school_time = $("#school_time").val();
    var school_year = $("#school_year").val();
    var type = $("#type").val();
    var status = $("#status").val();
    var avatar = $("#avatar").val();

    var json = {
        "name": name,
        "sex": sex,
        "cert": cert,
        "nation": nation,
        "birthday": birthday,
        "school": school,
        "edu": edu,
        "depart": depart,
        "class": class1,
        "pro": pro,
        "card": card,
        "edu_type": edu_type,
        "school_time": school_time,
        "school_year": school_year,
        "type": type,
        "status": status,
        "avatar": avatar
    };

    var url = $(e).attr('data-url');
    var target = $(e).attr('data-target');
    $.post(url, json, function (jsonData) {
        if (jsonData.status == 1) {
            location = target;
        } else {
            $.toast(jsonData.message);
        }
    }, "json");
}